﻿Partial Public Class ButtonClicks

    Private Sub gridLayoutRoot_Button_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        'wired up in XAML
        Debug.WriteLine("Layout Root Grid: " & DirectCast(e.Source, Button).Content.ToString)
    End Sub

    Private Sub Top_StackPanel_Button_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        'wired up in XAML
        Debug.WriteLine("Top StackPanel: " & DirectCast(e.Source, Button).Content.ToString)

        'change me and see what happens
        e.Handled = False
    End Sub

    Private Sub Bottom_StackPanel_Button_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        'wired up in XAML
        Debug.WriteLine("Bottom StackPanel: " & DirectCast(e.Source, Button).Content.ToString)

        'change me and see what happens
        e.Handled = False
    End Sub

    Private Sub btnLoneRanger_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnLoneRanger.Click
        'wired with Handler
        Debug.WriteLine("Lone Ranger Clicked")

        'change me and see what happens
        e.Handled = True
    End Sub

    Private Sub Window_Button_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        'wired in Window Loaded
        Debug.WriteLine("Window: " & DirectCast(e.Source, Button).Content.ToString & ", Is Handled: " & e.Handled)
    End Sub

    Private Sub ButtonClicks_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        'notice the last parameter = True.  This is the HandedEventsToo parameter.  defaults to False.  
        'allows the handling of "Handled" Routed Events after the the event has been handled in another event handler.
        Me.AddHandler(Button.ClickEvent, New RoutedEventHandler(AddressOf Window_Button_Click), True)

    End Sub

    Private Sub ButtonClicks_Unloaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Unloaded
        'VERY good habit to aquire, always unhook any events you hook up.
        Me.RemoveHandler(Button.ClickEvent, New RoutedEventHandler(AddressOf Window_Button_Click))
    End Sub


End Class
